package com.mission.scorepractice

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

/**
 * Created by KevenTao on 1/26/21.
 */
class MyViewModel : ViewModel() {
    val aScollValue: MutableLiveData<Int> by lazy {
        val scroll = MutableLiveData<Int>()
        scroll.value = 0
        scroll
    }
    public val bScollValue: MutableLiveData<Int> by lazy {
        val scroll = MutableLiveData<Int>()
        scroll.value = 0
        scroll
    }
    var aBeforeScroll = 0
    var bBeforeScroll = 0

    public fun aTeamAdd(n: Int) {
        aBeforeScroll = aScollValue.value ?: 0
        bBeforeScroll = bScollValue.value ?: 0
        aScollValue.value = aScollValue.value as Int + n
    }

    public fun bTeamAdd(n: Int) {
        aBeforeScroll = aScollValue.value ?: 0
        bBeforeScroll = bScollValue.value ?: 0
        bScollValue.value = bScollValue.value as Int + n
    }

    public fun reset(){
        aBeforeScroll = aScollValue.value ?: 0
        bBeforeScroll = bScollValue.value ?: 0
        aScollValue.value = 0
        bScollValue.value = 0
    }

    public fun undo(){
        aScollValue.value = aBeforeScroll
        bScollValue.value = bBeforeScroll
    }
}